{template 'web/_header'}
{template 'web/shop/tabs'}
{if $op== 'display'}
<form action="" method="post">
    <div class="panel panel-default">
        <div class="panel-body table-responsive">
            <table class="table table-hover">
                <thead class="navbar-inner">
                    <tr>
                        <th style='width:5%;'>ID</th>					
                        <th style='width:5%;'>活动标题</th>
                        <th style='width:10%;'>满减优惠</th>
                        <th style='width:10%;'>活动时间</th>
                        <th style='width:5%;'>创建时间</th>
                        <th style='width:5%;'>状态</th>
                        <th style='width:5%;'>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {loop $list $row}
                    <tr>
                        <td>{$row['id']}</td>
                        <td>{$row['title']}</td>
                        <td>{$row['em_id']}</td>
                        <td>{$row['starttime']}~{$row['endtime']}</td>
                        <td>{$row['createtime']}</td>
                        <td>
                            {if $row['status']==1}
                            <span class='label label-success' onclick="isshow(this, {$row['id']})">显示</span>
                            {else}
                            <span class='label label-danger' onclick="isshow(this, {$row['id']})">隐藏</span>
                            {/if}
                        </td>
                        <td>
                            <a href="{php echo $this->createWebUrl('shop/enoughmoney', array('op' => 'post', 'id' => $row['id']))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="修改"><i class="fa fa-edit"></i></a>
                            <!--<a href="{php echo $this->createWebUrl('shop/enoughmoney', array('op' => 'activity_delete', 'id' => $row['id']))}"class="btn btn-default btn-sm" onclick="return confirm('确认删除此活动?')" title="删除"><i class="fa fa-times"></i></a>-->
                        </td>
                    </tr>
                    {/loop}
                    <!--<tr>
                        <td colspan='1'>
                            <a class='btn btn-default' href="{php echo $this->createWebUrl('shop/enoughmoney',array('op'=>'post'))}"><i class='fa fa-plus'></i>添加活动</a>
                            <input type="hidden" name="token" value="{$_W['token']}" />
                        </td>
                    </tr>-->
                </tbody>
            </table>
            {$pager}
        </div>
    </div>
</form>
<script>
            require(['bootstrap'], function($) {
            $('.btn').hover(function() {
            $(this).tooltip('show');
            }, function() {
            $(this).tooltip('hide');
            });
            });</script>
<script>
            function isshow(obj, id){
            $(obj).html($(obj).html() + "...");
                    $.post("./index.php?c=site&a=entry&p=enoughmoney&op=activity_status_set&do=shop&m=ewei_shop", {id:id}, function(d){
                    $(obj).html($(obj).html().replace("...", ""));
                            if (d.result == 1){
                    $(obj).html(d.status == '1'?'显示':'隐藏');
                            $(obj).attr('class', d.status == 1?"label label-success":"label label-danger");
                    }
                    }
                    , "json"
                            );
            }
</script>
{/if}
{if $op == 'post'}
<form action="" method="get" class='form form-horizontal'>
    <div class="panel panel-info">
        <div class="panel-heading">筛选商品</div>
        <div class="panel-body">
            <form action="./index.php" method="get" class="form-horizontal" plugins="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="ewei_shop" />
                <input type="hidden" name="do" value="shop" />
                <input type="hidden" name="p"  value="enoughmoney" />
                <input type="hidden" name="op" value="post" />
                <input type="hidden" name="id" value="{$_GPC['id']}" />
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">商品名称</label>
                    <div class="col-xs-12 col-sm-8 col-lg-9">
                        <input class="form-control" name="goods_title" id="" type="text" value="{$_GPC['goods_title']}" placeholder="可搜索商品名称">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">是否选择</label>
                    <div class="col-xs-12 col-sm-8 col-lg-9">
                        <select name='goods_select' class='form-control'>
                            <option value='' {if $_GPC['goods_select']==''}selected{/if}></option>
                            <option value='1' {if $_GPC['goods_select']=='1'}selected{/if}>已选择</option>
                        </select> 
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">分类</label>
                    <div class="col-sm-8 col-xs-12">
                        {if intval($shopset['catlevel'])==3}
                        {php echo tpl_form_field_category_3level('category', $parent, $children, $params[':pcate'], $params[':ccate'], $params[':tcate'])}
                        {else}
                        {php echo tpl_form_field_category_2level('category', $parent, $children, $params[':pcate'], $params[':ccate'])}
                        {/if}
                    </div>
                    <div class="col-xs-12 col-sm-2 col-lg-2">
                        <button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="main">
        <form action="./index.php" method="get" class="form-horizontal" plugins="form">
            <input type="hidden" name="c" value="site" />
            <input type="hidden" name="a" value="entry" />
            <input type="hidden" name="m" value="ewei_shop" />
            <input type="hidden" name="do" value="shop" />
            <input type="hidden" name="p"  value="enoughmoney" />
            <input type="hidden" name="op" value="goods_select" />
            <div class="panel panel-default">
                <div class="panel-heading">
                    选择商品
                </div>
                <div class="panel-body">
                    <table class="table table-hover" id="goods">
                        <thead class="navbar-inner">
                            <tr>
                                <th style="width:5%;"><input type="checkbox" onclick="var ck = this.checked; $('#goods :checkbox').each(function(){this.checked = ck});">全选</th>
                                <th style="width:5%;">ID</th>					
                                <th style="text-align:center;">商品信息</th>
                                <th style="text-align:center;width:20%;">商品价格</th>
                                <th style="text-align:center;width:20%;">库存</th>
                                <th style="text-align:center;width:20%;">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {if $goods}
                            {loop $goods $li}
                            <tr>
                                <td><input type="checkbox" name="goods[]" value="{$li['id']}" {if $li['goodsid_select'] == '1'}checked{/if}></td>
                                <td>{$li['id']}</td>
                                <td><img src="http://oss-cn-shenzhen.aliyuncs.com/weixin-lanxue/{$li['thumb']}" style="width:30px;height:30px;border:1px solid $cc;padding:1px;">{$li['title']}</td>
                                <td style="text-align:center;">{$li['marketprice']}元</td>
                                <td style="text-align:center;">{$li['total']}件</td>
                                <td style="text-align:center;">
                                    <a href="{php echo $this->createWebUrl('shop/goods', array('op' => 'post', 'id' => $li['id']))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="查看商品详情"><i class="fa fa-edit"></i></a>
                                </td>
                            </tr>
                            {/loop}
                            <tr>
                                <td colspan='4'>
                                    <button class='btn btn-default' name='submit' value='1'><i class='fa fa-plus'></i>添加商品</button>
                                    <button class='btn btn-default' name='clear' value='1'>取消商品</button>
                                </td>
                            </tr>
                            {/if}
                        </tbody>
                    </table>
                    {$pager}
                </div>
            </div>
        </form>
    </div>
    <div class="main">
        <form  action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
            <div class="panel panel-default">
                <div class="panel-heading" style="cursor:pointer;" id="youhuishow">
                    满减活动设置
                </div>
                <div class="panel-body"  id="youhuicontain">
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">活动标题</label>
                        <div class="col-sm-9 col-xs-12">
                            <input type="text" id='title' name="title" class="form-control" value="{$activity['title']}" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">活动时间</label>
                        <div class="col-sm-9 col-xs-12">
                            {php echo tpl_form_field_daterange('time', array('starttime'=>date('Y-m-d H:i', $starttime),'endtime'=>date('Y-m-d  H:i', $endtime)),true);}
                        </div>
                    </div>
                    <!--<div class="form-group">
                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">选择商品</label>
                        <div class="col-sm-9  col-xs-12">
                            <select class="form-control" multiple="multiple" name="goods[]">
                                {if $goods}
                                {loop $goods $li}
                                <option value="{$li['id']}" {if $li['goodsid_select'] == '1'}selected{/if}>{$li['title']}</option>
                                {/loop}
                                {/if}
                            </select>
                        </div>
                    </div>-->
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                        <div class="col-sm-9 col-xs-12">
                            <div class="panel panel-default">
                                <div class="panel-heading" >
                                    满减优惠设置
                                </div>
                                <div class="panel-body">
                                    <table class="table table-hover" id="youhui">
                                        <thead class="navbar-inner">
                                            <tr>
                                                <th style="width:5%;"><input type="checkbox" onclick="var ck = this.checked; $('#youhui :checkbox').each(function(){this.checked = ck});">全选</th>
                                                <th style="width:5%;">层级</th>					
                                                <th style="text-align:center;">优惠门槛</th>
                                                <th style="text-align:center;">减少金额</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            {loop $manjianes $row}
                                            <tr>
                                                <td><input type="checkbox" name="em_id[]" value="{$row['id']}" {if $row['em_select'] == '1'}checked{/if}></td>
                                                <td>{$row['id']}</td>
                                                <td><label class="col-xs-12 col-sm-3 col-md-5 control-label" style="padding-right:0px;">满</label><div class="col-sm-2  col-xs-1" style="padding-left:5px;padding-right:5px;"><input type="text"  name="enoughmoney[]"  value="{$row['enoughmoney']}" class="form-control"/></div><label class=" control-label" style="padding-right:0px;">元</label></td>
                                                <td><label class="col-xs-12 col-sm-3 col-md-5 control-label" style="padding-right:0px;">减</label><div class="col-sm-2  col-xs-1" style="padding-left:5px;padding-right:5px;"><input type="text"  name="enoughdeduct[]"  value="{$row['enoughdeduct']}" class="form-control"/></div><label class=" control-label" style="padding-right:0px;">元</label></td>
                                            </tr>
                                            {/loop}
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">活动商品</label>
                        <div class="col-sm-9 col-xs-12">
                            <label class='radio-inline'>
                                <input type='radio' name='allgoods' value=0' {if $activity['allgoods']==0}checked{/if} />部分商品
                            </label>
                            <label class='radio-inline'>
                                <input type='radio' name='allgoods' value=1' {if $activity['allgoods']==1}checked{/if} />全部商品
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否显示</label>
                        <div class="col-sm-9 col-xs-12">
                            <label class='radio-inline'>
                                <input type='radio' name='status' value=1' {if $activity['status']==1}checked{/if} /> 是
                            </label>
                            <label class='radio-inline'>
                                <input type='radio' name='status' value=0' {if $activity['status']==0}checked{/if} /> 否
                            </label>
                        </div>
                    </div>
                    <div class="form-group"></div>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                        <div class="col-sm-9 col-xs-12">
                            <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"  />
                            <input type="hidden" name="token" value="{$_W['token']}" />
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    {/if}
    {if $op == 'set_list'}
    <form action="" method="post">
        <div class="panel panel-default">
            <div class="panel-body table-responsive">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                        <tr>
                            <th>ID</th>
                            <th>满金额</th>
                            <th>优惠金额</th>
                            <th>状态</th>
                            <th >操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {loop $list $row}
                        <tr>
                            <td>{$row['id']}</td>
                            <td>{$row['enoughmoney']}元</td>
                            <td>{$row['enoughdeduct']}元</td>
                            <td>
                                {if $row['status']==1}
                                <span class='label label-success' onclick="isshow(this, {$row['id']})">显示</span>
                                {else}
                                <span class='label label-danger'  onclick="isshow(this, {$row['id']})">隐藏</span>
                                {/if}
                            </td>
                            <td style="text-align:left;">
                                <a href="{php echo $this->createWebUrl('shop/enoughmoney', array('op' => 'set_post', 'id' => $row['id']))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="top" title="修改"><i class="fa fa-edit"></i></a>
                                <a href="{php echo $this->createWebUrl('shop/enoughmoney', array('op' => 'delete', 'id' => $row['id']))}"class="btn btn-default btn-sm" onclick="return confirm('确认删除?')" title="删除"><i class="fa fa-times"></i></a>
                            </td>
                        </tr>
                        {/loop}
                        <tr>
                            <td colspan='1'>
                                <a class='btn btn-default' href="{php echo $this->createWebUrl('shop/enoughmoney', array('op' => 'set_post'))}"><i class='fa fa-plus'></i>添加满减优惠</a>
                                <input type="hidden" name="token" value="{$_W['token']}" />
                            </td>
                        </tr>
                    </tbody>
                </table>
                {$pager}
            </div>
        </div>
    </form>
    <script>
                require(['bootstrap'], function($) {
                $('.btn').hover(function() {
                $(this).tooltip('show');
                }, function() {
                $(this).tooltip('hide');
                });
                });</script>
    <script>
                function isshow(obj, id){
                $(obj).html($(obj).html() + "...");
                        $.post("./index.php?c=site&a=entry&p=enoughmoney&op=status_set&do=shop&m=ewei_shop", {id:id}, function(d){
                        $(obj).html($(obj).html().replace("...", ""));
                                if (d.result == 1){
                        $(obj).html(d.status == '1'?'显示':'隐藏');
                                $(obj).attr('class', d.status == 1?"label label-success":"label label-danger");
                        }
                        }
                        , "json"
                                );
                }
    </script>
    {/if}
    {if $op=="set_post"}
    <div class="main">
        <form   method="post" class="form-horizontal form" enctype="multipart/form-data">
            <div class="panel panel-default">
                <div class="panel-heading">
                    满减设置
                </div>
                <div class="panel-body">
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">满金额</label>
                        <div class="col-sm-9 col-xs-12">
                            <input type="text" id='title' name="enoughmoney" class="form-control" value="{$enough['enoughmoney']}" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">优惠金额</label>
                        <div class="col-sm-9 col-xs-12">
                            <input type="text" name="enoughdeduct" class="form-control" value="{$enough['enoughdeduct']}" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否显示</label>
                        <div class="col-sm-9 col-xs-12">
                            <label class='radio-inline'>
                                <input type='radio' name='status' value=1' {if $enough['status']==1}checked{/if} /> 是
                            </label>
                            <label class='radio-inline'>
                                <input type='radio' name='status' value=0' {if $enough['status']==0}checked{/if} /> 否
                            </label>
                        </div>
                    </div>
                    <div class="form-group"></div>
                    <div class="form-group">
                        <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                        <div class="col-sm-9 col-xs-12">
                            <input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"  />
                            <input type="hidden" name="token" value="{$_W['token']}" />
                            <input type="button" name="back" onclick='history.back()' style='margin-left:10px;' value="返回列表" class="btn btn-default" />
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    {/if}
    {template 'web/_footer'}